package com.lqfan.autoAnswerQ.dao.user;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lqfan.autoAnswerQ.model.user.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  Mapper 用户的接口
 * </p>
 *
 * @author zmlin
 * @since 2020-04-09
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 创建用户
     * @param user
     * @return
     */
    @Insert("insert into user (id,userName,password,phone) values(#{id},#{userName},#{password},#{phone})")
    @Options(useGeneratedKeys = true ,keyProperty = "id" , keyColumn = "id")
    int insertUser(User user);

    /**
     * 检查账号是否存在
     * @param userName
     * @return
     */
    @Select("select * from user where userName= #{userName}")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    String findUser(String userName);

    /**
     * 登入验证
     * @param userName
     * @param password
     * @return
     */
    @Select("select * from user where userName=#{userName} and password=#{password}")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    String checkUser(String userName,String password);

    /**
     * 修改密码
     * @param userName
     * @param phone
     * @param password
     * @return
     */
    @Update("update user set password=#{password} where userName=#{userName} and phone=#{phone}")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    boolean updatePass(String userName,String phone,String password);
}
